package qin.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;

import qin.BookInformationSystem;

/**
 * 图书信息系统欢迎页
 * @author 小行星
 *
 */
public class BookInformationWelcomeView {
	private BookInformationSystem bookInformationSystem;
	private JFrame frame;
	private JLabel title;
	private JLabel hint;
	private JButton visitorButton;
	private JButton adminButton;
	
	public BookInformationWelcomeView(BookInformationSystem bookInformationSystem) {
		this.bookInformationSystem = bookInformationSystem;
		initialize();
	}
	
	/**
	 * 初始化
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setTitle("小行星绝佳赞助中");
		frame.getContentPane().setLayout(null);
		
		title = new JLabel("小行星图书信息管理系统欢迎您");
		title.setHorizontalAlignment(SwingConstants.CENTER);
		title.setForeground(Color.BLACK);
		title.setBackground(Color.WHITE);
		title.setFont(new Font("仿宋", Font.BOLD, 25));
		title.setBounds(33, 0, 377, 116);
		frame.getContentPane().add(title);
		
		hint = new JLabel("请选择右边两种方式之一登录");
		hint.setHorizontalAlignment(SwingConstants.CENTER);
		hint.setBounds(33, 126, 184, 90);
		frame.getContentPane().add(hint);
		
		visitorButton = new JButton("游客模式");
		visitorButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				bookInformationSystem.showBookInformationView();
			}
		});
		visitorButton.setBounds(273, 133, 93, 23);
		frame.getContentPane().add(visitorButton);
		
		adminButton = new JButton("管理模式");
		adminButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// 输入用户名和密码
				String pwd = (String)JOptionPane.showInputDialog(null, "管理员登录", "请输入密码", 2, null, null, "123456");
				if("123456".equals(pwd)) {
					bookInformationSystem.showAdminBookInformationView();
					bookInformationSystem.showBookInformationView();
				}else {
					JOptionPane.showMessageDialog(null, "密码错误", "管理员登录", 2);
				}
			}
		});
		adminButton.setBounds(273, 189, 93, 23);
		frame.getContentPane().add(adminButton);
	}
	
	public void switchVisable() {
		frame.setVisible(!frame.isVisible());
	}
}
